#pragma once
#include "Vector.h"
#include "AABBox.h"
#include "ActorEntity.h"
#include "voxelBrush.h"
namespace WL
{
	struct Voxel
	{
		//data
		const static int size = 4;
		VertexFormatVoxel	baseVertices[24];
		std::vector<VertexFormatVoxel> drawVertices;
		std::vector<INT32> drawIndices;
		CAABBox	aabb;
		Vec3F vec = { 0, 0, 0 };
		int nX = -1;
		int nY = -1;
		int nZ = -1;
		bool bShow = false;

		//Function
		void setVoxelSize(const Vec3F& fMin, const Vec3F& fMax);
	};


	class CVoxelChunk
	{
		friend class CVoxelMgr;
		friend class CVoxelTerrainBuild;

	public:
		CVoxelChunk();
		~CVoxelChunk();
		void buildChunkEntity();
		void generateGeometry();
		void createVoxel(const Vec3F& position);
		void createChunk(const Vec3F& position, const std::list<Vec3F>& voxels);
		const Vec3F& getPosition() const;
		bool checkBrushCollide(CVoxelBrush* pBrush);
		const CAABBox& getAABB()const;
		std::vector<Voxel*>& getVoxels();

	public:
		const static int nX = 16;
		const static int nY = 16;
		const static int nZ = 16;
		int			mUUID = 0;
		Vec3F		mPosition = {0,0,0};
		std::vector<VertexFormatVoxel*> mVertices;
		std::vector<VertexFormatVoxel> mDrawVertices;
		std::vector<UINT32> mDrawIndices;
		CAABBox	mAABB;		
		std::vector< std::vector< std::vector<Voxel*>>> mVoxelArray;
		std::vector<Voxel*> mVoxels;
		CActorEntity* mpActorEntity = nullptr;
		std::string mszName;

#ifdef _DEBUG
		CActorEntity* mpNormalEntity = nullptr;
#endif
	};
}